<template>
	<view class="more">
		<!-- <view class="search-view">
			<u-search :placeholder="$t('searchResult.search')" :disabled="true" :show-action="false" @click="clickSearch" height="37">
			</u-search>
		</view> -->

		<view class="screen">
			<view class="commodity-list" v-if="goodsList">
				<waterfallsFlow imageSrcKey="seriesOne" :list="goodsList">
					<template v-slot:default="item">
						<GoodsItem :isNoImg="true" v-if="item.status == 1 || item.status == 3" :isClick="true" :goodsItem="item"
							></GoodsItem>
					</template>
				 </waterfallsFlow >
			</view>
		</view>

		<view class="none-search" v-if="show">
			<view class="none-top">
				<image src="../../static/icon/image_37.png" mode=""></image>
				<view class="none-desc">
					{{$t('searchResult.hint1')}}<br>
					{{$t('searchResult.hint2')}}
				</view>
			</view>

			<view class="none-bottom" @tap="goWishList">
				{{$t('searchResult.hint3')}}
			</view>
		</view>
	</view>
</template>

<script>
	import search from '@/components/search.vue'
	import GoodsItem from '@/components/GoodsItem/GoodsItem.vue'
	import {
		getSearchGoods,
		addSearchHistory
	} from "@/common/api.js"
	import waterfallsFlow from "@/components/maramlee-waterfalls-flow/maramlee-waterfalls-flow.vue";

	export default {
		components: {
			search,
			GoodsItem,
			waterfallsFlow
		},
		data() {
			return {
				screenCurrent: 0,
				item: null,
				goodsList: [],
				searchValue: null,
				show: false,
				want: null,
			}
		},
		methods: {
			clickSearch() {
				if(this.want) {
					uni.redirectTo({
						url: "/pages/search/search?want=1"
					})
				} else {
					uni.redirectTo({
						url: "/pages/search/search"
					})
				}
			},
			async initData() {
				let res = null;
				
				if(this.want) {
					res = await getSearchGoods({
						searchValue: this.searchValue,
						status: 11
					})
				} else {
					res = await getSearchGoods({
						searchValue: this.searchValue,
						status: 1
					})
				}
				const historyRes = await addSearchHistory({
					content: this.searchValue
				});
				console.log(res);
				console.log(historyRes);
				if (res.code === 200 && res.rows.length <= 0) {
					this.show = true;
					return;
				}
				this.goodsList = res.rows;
				// console.log(this.goodsList);
			},
			goWishList() {
				uni.navigateTo({
					url: "/pages/wishList/wishList"
				})
			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t("searchResult.title")
			});
		},
		onLoad(option) {
			this.searchValue = option.searchValue;
			console.log(option);
			if(option.want) {
				this.want = option.want;
			}
			this.initData();
		},
		// onBackPress(e) {
		// 	uni.navigateBack();
		// 	return true;
		// },
	}
</script>

<style scoped lang="scss">
	.swiper-view {
		margin: 14rpx 0px;
		margin-top: 102rpx;
	}

	.search-view {
		padding: 14rpx 22rpx;
		position: fixed;
		/* #ifdef APP */
		top: 0;
		/* #endif */
		
		/* #ifdef H5 */
		top: 86rpx;
		/* #endif */
		left: 0;
		right: 0;
		z-index: 1;
		background-color: #fff;
	}

	.screen-bar {
		width: 100%;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		background: #FFFFFF;
		box-shadow: 0rpx -2rpx 16rpx 0rpx #0000000C;
		height: 88rpx;
		display: flex;
		align-items: center;
		color: #717184;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 26rpx;

		.sreen-left {
			width: 82%;
			display: flex;
			align-items: center;
			justify-content: center;
			border-right: 5rpx solid #858585;

			.comp {
				margin-right: 155rpx;
			}

			.sales {}
		}

		.filter {
			width: 18%;
			margin-left: 30rpx;
		}
	}

	.active {
		color: #FAAD67;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 26rpx;
	}

	.screen {
		width: 100%;
		background: #FBFBFB;
		box-shadow: 0px -1px 8px rgba(0, 0, 0, 0.1);
		border-radius: 10px;
	}

	.more {
		padding: 0rpx 24rpx;
		width: 100%;
		box-sizing: border-box;
	}

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}

	.commodity-list {
		// margin-top: 102rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 30rpx;
	}

	.none-search {
		width: 440rpx;
		margin: 250rpx auto;

		.none-top {
			height: 250rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			background: rgba(151, 151, 151, 0.5);
			border-radius: 10px 10px 0px 0px;

			image {
				width: 88rpx;
				height: 88rpx;
			}

			.none-desc {
				margin-top: 20rpx;
				font-family: 'PingFang SC';
				font-style: normal;
				font-weight: 400;
				font-size: 30rpx;
				color: #fff;
			}
		}

		.none-bottom {
			height: 78rpx;
			font-family: 'PingFang SC';
			font-style: normal;
			font-weight: 400;
			font-size: 30rpx;
			color: #0085FF;
			background: rgba(151, 151, 151, 0.5);
			border-bottom: 2rpx solid #E7E7E7;
			border-radius: 0 0 20rpx 20rpx;
			text-align: center;
			line-height: 78rpx;
			margin-top: 2rpx;
		}
	}
</style>
